package 实训训练.work;

import java.util.*;

public class demo01 {
    public static int i=1;
   static Scanner scanner=new Scanner(System.in);

    public static void main(String[] args) {
        List<Student> list=new ArrayList<Student>();
        list.sort(new Comparator<Student>() {
            @Override
            public int compare(Student s1, Student s2) {
                int num=s1.getsum()-s2.getsum();
                int num2=num==0?s1.getName().compareTo(s2.getName()):num;
                return num2;
            }
        });
        Iterator<Student> iterator=list.listIterator();
        while (iterator.hasNext()){
            if (iterator.next().getsum()==0){
                iterator.remove();
            }
        }
        Map<String,List<Student>> stringListMap=new HashMap<String,List<Student>>();


        while (true){
            System.out.println("*********1.添加学生******2.删除学生******3.查询学生*****");
            System.out.println("请输入你要操作的指令:");
            int i=scanner.nextInt();
            switch (i){
                case 1:
                    add(list,stringListMap);
                    break;
                case 2:
                    System.out.println("请输入你要删除的序号");
                    String i1=scanner.next();

                    System.out.println(stringListMap.remove(i1));
                    System.out.println("已删除");
                    break;
                    case 3:
                        System.out.println("请输入你要查询的序号");
                        System.out.println(list);
                        String i2=scanner.next();
                        System.out.println(stringListMap.get(i2));
                        List<Student> list1 = stringListMap.get(i2);
                        for (Student s:list1){
                            System.out.println(s.getsum());
                        }

//                        Set<Integer> kt=stringListMap.keySet();
//                        for (Integer integer:kt){
//                            stringListMap.get(integer);
//
//                        }
//
                        break;
                default:
                    System.out.println("输入错误!");
            }
        }
    }
    public static void add(List<Student> list,Map<String, List<Student>> map){
        System.out.println("请输入学生的id");
        int ids = scanner.nextInt();
        System.out.println("请输入学生的姓名");
        String name = scanner.next();
        System.out.println("请输入学生的语文成绩");
        int che = scanner.nextInt();
        System.out.println("请输入学生的数学成绩");
        int math = scanner.nextInt();
        System.out.println("请输入学生的英语成绩");
        int english = scanner.nextInt();
        Student s1 = new Student(ids, name, che, math, english);
        list.add(s1);
        map.put(String.valueOf(ids),list);

        System.out.println("添加成功");
//        int i=1;
//        map.put(i,list);
//        i++;

    }
}
